from enums.custom import CustomDictService
from packages.engine.assignment_handler import AssignmentHandler
from packages.engine.util.reflect_util import ReflectUtil


class AssignmentHandlerCustomDict(CustomDictService):
    dictModel = {}

    def __init__(self) -> None:
        self.dictModel = {}

    def get_by_dict_key(self, args: dict) -> dict:
        if args.get("dictType") == "wf_assignment_handler":
            return self.get_dict_model()
        return None

    def get_dict_model(self) -> dict:
        classList = ReflectUtil.find_class_from_dirs(
            ["services/flow"], AssignmentHandler
        )
        items = []
        for clazz in classList:
            items.append({
                "name": clazz.__message__,
                "dictItemValue": clazz.__code__,
                "dictItemKey": clazz.__code__,
            })
        self.dictModel = {
            "dictKey": "wf_assignment_handler",
            "name": "工作流参与者处理类",
            "items": items
        }
        return self.dictModel
